﻿
using System;

public class SLTToken
{
    private bool _IsSsoProxyToken = false;
    private bool _IsMigrated = false;
    private string _Token = String.Empty;

    public bool IsSsoProxyToken
    {
        get
        {
            return _IsSsoProxyToken;
        }
        private set
        {
            _IsSsoProxyToken = value;
        }
    }

    public bool IsMigrated
    {
        get
        {
            return _IsMigrated;
        }
        private set
        {
            _IsMigrated = value;
        }
    }

    public string Token
    {
        get
        {
            return _Token;
        }
        private set
        {
            _Token = value;
        }
    }

    public SLTToken(string slt)
    {
        const string Office365Prefix = "O365";
        const string WlidPrefix = "WLID";
        const int MaxSplitCount = 2;

        string[] sltTokens = slt.Split(new char[]{':'}, MaxSplitCount);
        if (sltTokens.Length == MaxSplitCount
            && (sltTokens[0].Equals(WlidPrefix, StringComparison.OrdinalIgnoreCase)
                || sltTokens[0].Equals(Office365Prefix, StringComparison.OrdinalIgnoreCase)))
        {
            this.IsSsoProxyToken = true;
            this.IsMigrated = sltTokens[0].Equals(Office365Prefix, StringComparison.OrdinalIgnoreCase);
            this.Token = sltTokens[1];
        }
        else
        {
            this.IsSsoProxyToken = false;
            this.IsMigrated = false;
            this.Token = slt;
        }
    }
}